package com.jingxi.portal.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.jingxi.common.pojo.JingXiResult;
import com.jingxi.portal.pojo.ItemInfo;
import com.jingxi.portal.service.ItemService;

@Controller
public class ItemController {

	@Autowired
	private ItemService itemService;
	
	@RequestMapping("/item/{itemId}")
	public String showItem(@PathVariable Long itemId,Model model) {
		ItemInfo item = itemService.getItemById(itemId);
		model.addAttribute("item",item);
		return "goods";
	}
	@RequestMapping(value="/item/desc/{itemId}",produces="text/html;charset=utf-8")
	@ResponseBody
	public String getItemDesc(@PathVariable Long itemId) {
		return itemService.getItemDescById(itemId);
	}
	@RequestMapping(value="/item/param/{itemId}",produces="text/html;charset=utf-8")
	@ResponseBody
	public String getItemParam(@PathVariable Long itemId) {
		return itemService.getItemParam(itemId);
	}
	
	@RequestMapping(value="/item/route/{pid}",produces="application/json;charset=utf-8")
	@ResponseBody
	public JingXiResult getItemFrom(@PathVariable Long pid) {
		JingXiResult result = itemService.getRouteFromPid(pid);
		System.out.println(result.getStatus() +"-" + result.getMsg());
		return result;
	}
}
